package com.caption.core.executor;

import org.springframework.stereotype.Component;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;

@Component
public class WorkExecutorManager {
    /**
     * 执行没有返回结果
     * @param workExecutorName
     * @param task
     */
    public void execute(String workExecutorName,Runnable task){
        ExecutorService executorService = WorkExecutorFactory.getWorkExecutor(workExecutorName);
        executorService.execute(task);
    }

    /**
     * 执行有结果返回
     * @param workExecutorName
     * @param task
     * @return
     */
    public Future<?> submit(String workExecutorName, Callable<?>task){
        ExecutorService executorService = WorkExecutorFactory.getWorkExecutor(workExecutorName);
        return executorService.submit(task);
    }
}
